<?php



/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Education
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */
 
 
 
class Education_Widget_ListEducationsController extends Engine_Content_Widget_Abstract
{

  public function indexAction()
  {
  	
    // Don't render this if not authorized
    $viewer = Engine_Api::_()->user()->getViewer();
  

    $params = array(
      'order' => $this->_getParam('order', 'recent'),
      'limit' => $this->_getParam('max', 5),
    );
    
    if ($user = $this->_getParam('user')) {
      $params['user'] = $user;
    }
    
    if ($category = $this->_getParam('category')) {
      $params['category'] = $category;
    }

    if ($period = $this->_getParam('period')) {
      $params['start_date'] = time() - $period * 86400;
    }
    
    if ($this->_getParam('featured', 0)) {
      $params['featured'] = 1;
    }
    
    $this->view->paginator = $paginator = Engine_Api::_()->education()->getEducationsPaginator($params);

    $this->view->display_style = $this->_getParam('display_style', 'wide');
    
    $this->view->showphoto = $this->_getParam('showphoto', $this->view->display_style == 'narrow' ? 0 : 1);
    $this->view->showdetails = $this->_getParam('showdetails', $this->view->display_style == 'narrow' ? 1 : 1); 
    
    $this->view->showmeta = $this->_getParam('showmeta', $this->view->display_style == 'narrow' ? 0 : 1); 
    $this->view->showdescription = $this->_getParam('showdescription', $this->view->display_style == 'narrow' ? 0 : 0); 
    
    $this->view->order = $params['order'];
    
    // Do not render if nothing to show
    if( $paginator->getTotalItemCount() <= 0 ) {
      return $this->setNoRender();
    }
    
  }

}